/****************************************************/
// Theme name: Nexus - Bootstrap Admin Template
// Theme URI: http://nexus.lethemes.net/1.0/html/
// Description: Nexus is a fully responsive admin dashboard template
// Tags: admin, admin dashboard, cms, crm, project managerment, responsive, webapp, backend, bootstrap admin, responsive admin
// Author: Loi Le
// Version: 1.0
/****************************************************/

var calendar = $('#fullcalendar').fullCalendar({
    defaultView: 'agendaWeek',
    header: {
        left: 'title',
        right: 'agendaDay, agendaWeek, month, today, prev, next'
    },
    editable: true,
    selectable: true,
    select: function(start, end, allDay) {
        $('#start').val(moment(start).format("YYYY/MM/DD hh:mm a"));
        $('#end').val(moment(end).format("YYYY/MM/DD hh:mm a"));
        $('#inputTitleEvent').val(''),
        $('#addNewEvent').modal('show');
    }
});

$('#btnAddNewEvent').on('click', function(e) {
    e.preventDefault();
    addNewEvent();
});

function addNewEvent() {
    $("#addNewEvent").modal('hide');
    $("#fullcalendar").fullCalendar('renderEvent', {
        title: $('#inputTitleEvent').val(),
        start: new Date($('#start').val()),
        end: new Date($('#end').val()),
        backgroundColor: $('#inputBackgroundEvent').val(),
        borderColor: '#FFF'
    }, true);
}

/* initialize the external events
-----------------------------------------------------------------*/
$('.draggable li').each(function() {
    // store data so the calendar knows to render an event upon drop
    $(this).data('event', {
        title: $.trim($(this).text()), // use the element's text as the event title
        stick: true // maintain when user navigates (see docs on the renderEvent method)
    });
    // make the event draggable using jQuery UI
    $(this).draggable({
        zIndex: 999,
        revert: true, // will cause the event to go back to its
        revertDuration: 0 //  original position after the drag
    });
});
/* initialize the calendar
-----------------------------------------------------------------*/
$('#fullcalendar2').fullCalendar({
    header: {
        left: 'prev,next',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    editable: true,
    droppable: true, // this allows things to be dropped onto the calendar
    drop: function() {
        // is the "remove after drop" checkbox checked?
        if ($('#drop-remove').is(':checked')) {
            // if so, remove the element from the "Draggable Events" list
            $(this).remove();
        }
    },
    eventColor: '#16A085'
});

// jQuery MiniColors
// --------------------------------------------------
$('.colorpicker').each(function() {
    //
    // Dear reader, it's actually very easy to initialize MiniColors. For example:
    //
    //  $(selector).minicolors();
    //
    // The way I've done it below is just for the demo, so don't get confused
    // by it. Also, data- attributes aren't supported at this time...they're
    // only used for this demo.
    //
    $(this).minicolors({
        control: $(this).attr('data-control') || 'hue',
        defaultValue: $(this).attr('data-defaultValue') || '',
        inline: $(this).attr('data-inline') === 'true',
        letterCase: $(this).attr('data-letterCase') || 'lowercase',
        opacity: $(this).attr('data-opacity'),
        position: $(this).attr('data-position') || 'bottom left',
        showSpeed: 0,
        change: function(hex, opacity) {
            if (!hex) return;
            if (opacity) hex += ', ' + opacity;
            if (typeof console === 'object') {
                console.log(hex);
            }
        },
        show: function() {
            $(this).nextAll('.minicolors-panel').animo({
                animation: 'fadeInUp',
                duration: .3
            });
        },
        theme: 'bootstrap'
    });
});